<?php
	class BeneficiaryModel extends CI_Model
	{
		public function __construct()
		{
			$this->load->database();
		}
		public final function addBeneficiary($beneficiary)
		{
			$b = $beneficiary;
			$a = array
			(
				'FullName' => $b->FullName,
				'Needs' => $b->Needs,
				'Conditions' => $b->Conditions,
				'NeededDonation' => $b->NeededDonation,
				'CurrentDonation' => $b->CurrentDonation,
				'EventId' => $b->EventId,
				'NgoId' => $b->NgoId
			);
			$this->db->insert('beneficiaries', $a);
			return $this->db->insert_id();
		}
		public final function getAllBeneficiaries()
		{
			$q = $this->db->get('beneficiaries');
			return $q->result_object();
		}
		public final function getBeneficiaryById($id)
		{
			$q = $this->db->get_where('beneficiaries', array('Id' => $id));
			return $q->result_object();
		}
		public final function updateBeneficiary($beneficiary)
		{
			$b = $beneficiary;
			$a = array
			(
				'FullName' => $b->FullName,
				'Needs' => $b->Needs,
				'Conditions' => $b->Conditions,
				'NeededDonation' => $b->NeededDonation,
				'CurrentDonation' => $b->CurrentDonation,
				'EventId' => $b->EventId,
				'NgoId' => $b->NgoId
			);
			$this->db->where('Id', $b->Id);
			$this->db->update('beneficiaries', $a);
		}
		public final function removeBeneficiaryById($id)
		{
			$this->db->delete('beneficiaries', array('Id' => $id));
		}
	}